#ifndef _MSG_H
#define _MSG_H

#include "config.h"

typedef enum
{
    MSG_TYPE_CTRL = 0,      // 控制
    MSG_TYPE_CSV,           // 召唤
    MSG_TYPE_PASS,          // 透传
    MSG_TYPE_ALM_YX,        // 遥信类告警
    MSG_TYPE_ALM_THRESHOLD, // 阈值类告警
    MSG_TYPE_ALM_DEV,       // 偏差告警
    MSG_TYPE_ALM_RATE       // 变化率告警
} msg_type_t;

#define MAX_KV_CHAR_SIZE 30
#define MAX_DESP_SIZE 256
#define MAX_STREAM_SIZE 300

typedef struct
{
    int rate_cycle;
    int rate_value;
    float current_val;
} msg_alarm_rate_t;

typedef struct
{
    int deviatio_value;
    int deviatio_set;
    float current_val;
} msg_alarm_deviation_t;

typedef struct
{
    int type;    // 0--LL;1-LO;2-HI;3-HH
    float threshold;
    float current_val;
} msg_alarm_threshold_t;

typedef struct
{
    uint8_t normal_val;
    uint8_t current_val;
} msg_alarm_yx_t;

typedef struct kv_s
{
    char key[MAX_KV_CHAR_SIZE];
    char value[MAX_KV_CHAR_SIZE];
} kv_t;

typedef struct
{
    int cnt;
    uint8_t stream[MAX_STREAM_SIZE];
}msg_pass_t;

typedef struct
{
    msg_type_t type; // 消息类型
    int ts;          // 时间戳
    char *su;        // 设备id
    char *ch;        // 通道id

    void *value;
} msg_t;


// 定义消息函数
// 返回值 --> 0--成功，-1失败
typedef int (*fmsg)(cfg_pu_t* pu, msg_t *data);


#endif
